package com.sgb.kjwl.viewmodel.chat;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.harisucici.jetpackbase.base.HBaseViewModel;
import com.qgb.zcore.mmkvutil.CacheMarker;
import com.qgb.zcore.mmkvutil.MkvUtils;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.chat.NewsMenuEntity;
import com.sgb.kjwl.model.entity.chat.NewsNoticeEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ChatNewsModel extends HBaseViewModel {

    public MutableLiveData<List<NewsMenuEntity>> menuList = new MutableLiveData<>();
    public MutableLiveData<List<NewsMenuEntity>> newMenuList = new MutableLiveData<>();

    public MutableLiveData<List<NewsNoticeEntity>> NoticeList1 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList2 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList3 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList4 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList5 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList6 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList7 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList8 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList9 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList10 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList11 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList12 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList13 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList14 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList15 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeList16 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore1 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore2 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore3 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore4 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore5 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore6 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore7 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore8 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore9 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore10 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore11 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore12 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore13 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore14 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore15 = new MutableLiveData<>();
    public MutableLiveData<List<NewsNoticeEntity>> NoticeListMore16 = new MutableLiveData<>();

    public ChatNewsModel(@NonNull Application application) {
        super(application);
    }

    /**
     * 初始化获取菜单列表
     */
    public List<NewsMenuEntity> getMenuList() {
        List<NewsMenuEntity> list = new ArrayList<>();
        list.add(new NewsMenuEntity(0, "会话", ""));
        list.add(new NewsMenuEntity(0, "订单", ""));
        list.add(new NewsMenuEntity(0, "询价", ""));
        list.add(new NewsMenuEntity(0, "函询", ""));
        list.add(new NewsMenuEntity(0, "邀请", ""));
        return list;
    }

    /**
     * 获取通知类型列表
     *
     * @param timelineId 通知会话ID
     * @param type       1:首页请求菜单 2:通知界面请求菜单
     */
    public void getNoticeMenuList(String timelineId, String type) {
        Map map = new HashMap();
        String imAccount = MkvUtils.get().getString(MkvUtils.UserData, CacheMarker.ImAccount, "");
        map.put("userId", imAccount);
        map.put("timelineId", timelineId);
        map.put("type", type);
        APIManager.getInstance().getIMServiceAPI().getNewsMenuList(map).enqueue(new ICallBack<BaseEntity<List<NewsMenuEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<NewsMenuEntity>> data) {
                menuList.postValue(data.getData());
            }
        });
    }

    /**
     * 获取通知类型列表
     *
     * @param timelineId 通知会话ID
     * @param type       1:首页请求菜单 2:通知界面请求菜单
     */
    public void getNewNoticeMenuList(String timelineId, String type) {
        Map map = new HashMap();
        String imAccount = MkvUtils.get().getString(MkvUtils.UserData, CacheMarker.ImAccount, "");
        map.put("userId", imAccount);
        map.put("timelineId", timelineId);
        map.put("type", type);
        APIManager.getInstance().getIMServiceAPI().getNewsMenuList(map).enqueue(new ICallBack<BaseEntity<List<NewsMenuEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<NewsMenuEntity>> data) {
                newMenuList.postValue(data.getData());
            }
        });
    }

    /**
     * 根据类型查询通知列表
     *
     * @param timelineId 通知会话ID
     * @param type       通知类型
     * @param page       当前的页数
     */
    public void getNoticeListByType(String timelineId, String type, int page, boolean isLoadMore) {
        Map map = new HashMap();
        map.put("page", page);
        map.put("size", 10);
        map.put("timelineId", timelineId);
        map.put("type", type);
        String imAccount = MkvUtils.get().getString(MkvUtils.UserData, CacheMarker.ImAccount, "");
        map.put("userId", imAccount);
        APIManager.getInstance().getIMServiceAPI().getNoticeListByType(map).enqueue(new ICallBack<BaseEntity<List<NewsNoticeEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<NewsNoticeEntity>> data) {
//                Collections.reverse(data.getData());
                if (!isLoadMore) {
                    switch (type) {
                        case "order"://订单
                            NoticeList1.postValue(data.getData());
                            break;
                        case "enquiry_price"://询价
                            NoticeList2.postValue(data.getData());
                            break;
                        case "letter_inquiries"://函询
                            NoticeList3.postValue(data.getData());
                            break;
                        case "invite"://邀请
                            NoticeList4.postValue(data.getData());
                            break;
                        case "material"://商品材料
                            NoticeList5.postValue(data.getData());
                            break;
                        case "recruitment"://招标竞价
                            NoticeList6.postValue(data.getData());
                            break;
                        case "group_purchase"://集团采购
                            NoticeList7.postValue(data.getData());
                            break;
                        case "lease"://租赁转让
                            NoticeList8.postValue(data.getData());
                            break;
                        case "work_team"://工队工人
                            NoticeList9.postValue(data.getData());
                            break;
                        case "logistics"://物流货运
                            NoticeList10.postValue(data.getData());
                            break;
                        case "member_operating"://会员经营
                            NoticeList11.postValue(data.getData());
                            break;
                        case "company_operating"://企业经营
                            NoticeList12.postValue(data.getData());
                            break;
                        case "company_server"://企业服务
                            NoticeList13.postValue(data.getData());
                            break;
                        case "attract_investment"://招商引资
                            NoticeList14.postValue(data.getData());
                            break;
                        case "business_server"://商机服务
                            NoticeList15.postValue(data.getData());
                            break;
                        case "system_notify"://系统通知
                            NoticeList16.postValue(data.getData());
                            break;
                    }
                } else {
                    switch (type) {
                        case "order"://订单
                            NoticeListMore1.postValue(data.getData());
                            break;
                        case "enquiry_price"://询价
                            NoticeListMore2.postValue(data.getData());
                            break;
                        case "letter_inquiries"://函询
                            NoticeListMore3.postValue(data.getData());
                            break;
                        case "invite"://邀请
                            NoticeListMore4.postValue(data.getData());
                            break;
                        case "material"://商品材料
                            NoticeListMore5.postValue(data.getData());
                            break;
                        case "recruitment"://招标竞价
                            NoticeListMore6.postValue(data.getData());
                            break;
                        case "group_purchase"://集团采购
                            NoticeListMore7.postValue(data.getData());
                            break;
                        case "lease"://租赁转让
                            NoticeListMore8.postValue(data.getData());
                            break;
                        case "work_team"://工队工人
                            NoticeListMore9.postValue(data.getData());
                            break;
                        case "logistics"://物流货运
                            NoticeListMore10.postValue(data.getData());
                            break;
                        case "member_operating"://会员经营
                            NoticeListMore11.postValue(data.getData());
                            break;
                        case "company_operating"://企业经营
                            NoticeListMore12.postValue(data.getData());
                            break;
                        case "company_server"://企业服务
                            NoticeListMore13.postValue(data.getData());
                            break;
                        case "attract_investment"://招商引资
                            NoticeListMore14.postValue(data.getData());
                            break;
                        case "business_server"://商机服务
                            NoticeListMore15.postValue(data.getData());
                            break;
                        case "system_notify"://系统通知
                            NoticeListMore16.postValue(data.getData());
                            break;
                    }
                }
            }
        });
    }

}
